package com.mytest.leetcode.middle;

import lombok.extern.slf4j.Slf4j;

import java.util.Arrays;

/**
 * Created by shixi  on 2019/6/24
 */
@Slf4j
public class Solution881 {

    public static void main(String[] args) {
        Solution881 solution = new Solution881();
//        int [] nums = {2,4,7,3,5,9};
        int [] nums = {3,5,3,4};
        int limit = 5;
        log.info("{}",solution.numRescueBoats(nums, limit));
    }


    public int numRescueBoats(int[] people, int limit) {
        int num = people.length - 1;
        Arrays.sort(people);
        int start = 0;
        int result = 0;
        while (start <= num) {
            if (people[start] + people[num] <= limit){
                start++;
            }
            num--;
            result++;
        }
        return result;
    }
}

